package com.binance.notification.web.controller;

import com.binance.master.models.APIRequest;
import com.binance.master.models.APIResponse;
import com.binance.notification.api.MessagePushApi;
import com.binance.notification.api.request.LongIdRequest;
import com.binance.notification.api.request.MessagePushRequest;
import com.binance.notification.api.request.MessageTypeRequest;
import com.binance.notification.api.request.MessageUpdateRequest;
import com.binance.notification.api.response.MessagePushBodyPageResponse;
import com.binance.notification.api.response.MessagePushPageResponse;
import com.binance.notification.api.response.MessageTypePageResponse;
import com.binance.notification.api.response.MessageTypeResponse;
import com.binance.notification.api.vo.MessagePushVo;
import com.binance.notification.web.service.IMessagePushService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author lufei
 * @date 2018/11/2
 */
@RestController
public class MessagePushController implements MessagePushApi {

    @Resource
    private IMessagePushService messagePushService;

    @Override
    public APIResponse<Void> addType(@RequestBody APIRequest<MessageTypeRequest> request) {
        messagePushService.addType(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> updateType(@RequestBody APIRequest<MessageTypeRequest> request) {
        messagePushService.updateType(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> deleteType(@RequestBody @Validated APIRequest<LongIdRequest> request) {
        messagePushService.deleteType(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<MessageTypeResponse> getTypeById(@RequestBody @Validated APIRequest<LongIdRequest> request) {
        MessageTypeResponse response = messagePushService.getTypeById(request.getBody());
        return APIResponse.getOKJsonResult(response);
    }

    @Override
    public APIResponse<MessageTypePageResponse> getTypeList(@RequestBody APIRequest<MessageTypeRequest> request) {
        MessageTypePageResponse response = messagePushService.getTypeList(request.getBody());
        return APIResponse.getOKJsonResult(response);
    }

    @Override
    public APIResponse<Void> saveOrUpdateMessagePush(@RequestBody @Validated APIRequest<MessagePushRequest> request) {
        messagePushService.saveOrUpdateMessagePush(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<MessagePushVo> getById(@RequestBody APIRequest<LongIdRequest> request) {
        MessagePushVo response = messagePushService.getById(request.getBody());
        return APIResponse.getOKJsonResult(response);
    }

    @Override
    public APIResponse<MessagePushPageResponse> getList(@RequestBody APIRequest<MessagePushRequest> request) {
        MessagePushRequest body = request.getBody();
        MessagePushVo vo = body.getVo();
        MessagePushPageResponse response = messagePushService.getList(vo.getId(), vo.getType(), vo.getRemark(), vo.getStatus(), body.getOffset(), body.getRows());
        return APIResponse.getOKJsonResult(response);
    }

    @Override
    public APIResponse<MessagePushBodyPageResponse> getMessagePushBodyList(@RequestBody APIRequest<LongIdRequest> request) {
        MessagePushBodyPageResponse response = messagePushService.getMessagePushBodyList(request.getBody());
        return APIResponse.getOKJsonResult(response);
    }

    @Override
    public APIResponse<Void> refuseNotice(@RequestBody @Validated APIRequest<MessageUpdateRequest> request) {
        messagePushService.refuseNotice(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> delete(@RequestBody @Validated APIRequest<LongIdRequest> request) {
        messagePushService.delete(request.getBody());
        return APIResponse.getOKJsonResult();
    }

    @Override
    public APIResponse<Void> send(@RequestBody @Validated APIRequest<MessageUpdateRequest> request) {
        messagePushService.send(request.getBody());
        return APIResponse.getOKJsonResult();
    }

}
